import dayjs from 'dayjs';

/**
 * @description: 时间类型转换
 * @param {string} time
 * @param {string} format
 */
export const setTime = (time: string, format: string = 'YYYY-MM-DD HH:mm') => (time ? dayjs(time).format(format) : null);

/**
 * @description: 分钟装换 天、小时、分钟
 * @param {string} minute
 */
export const setHour = (minute: string | number) => {
  if (!minute) return minute;
  let _m = typeof minute === 'string' ? parseInt(minute) : minute;
  let h = Math.floor(_m / 60);

  const m = _m % 60;
  const day = h > 24 ? (h / 24).toFixed(0) : 0;
  if (day) {
    h = h % 24;
  }
  return `${day ? day + '天' : ''}${h ? h + '时' : ''}${m}分`;
};
